<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
		<title>讨论章节窗口页</title>
		<link rel="stylesheet" href="../../css/mui.min.css" />
		<link rel="stylesheet" href="../../css/timecontrol.min.css" />
		<link rel="stylesheet" href="../../css/base.css"/>
		<link rel="stylesheet" type="text/css" href="../../css/weui.min.css">
		<link rel="stylesheet" type="text/css" href="../../css/study.css" />
		<style>
			html body {
				background-color: #F3F5F7;
				padding: 0;
				margin: 0;
			}
			.btn_submit1 {
				color: #333;
				width: 50%;
				background: url(../../icon/add_discuss.png) no-repeat 25% center;
				background-size: 20px;
				background-color: #FFFFFF;
				border: 1px solid #dedede;
				font-size: 16px;
				padding-left: 18px;
				margin-left: 18px;
			}
			.btn_submit2 {
				color: #FFFFFF;
				width: 50%;
				background: url(../../icon/close_discuss.png) no-repeat 25% center;
				background-size: 20px;
				background-color: #FF9900;
				border: 1px solid #FF9900;
				font-size: 16px;
				padding-left: 18px;
				margin-left: 18px;
			}
			.horcenter1 {
				position: absolute;
				left: 25%;
				-webkit-transform: translate(-50%,0);
				-ms-transform: translate(-50%,0);
				-o-transform: translate(-50%,0);
				transform: translate(-50%,0);
			}
			.horcenter2 {
				position: absolute;
				left: 75%;
				-webkit-transform: translate(-50%,0);
				-ms-transform: translate(-50%,0);
				-o-transform: translate(-50%,0);
				transform: translate(-50%,0);
			}
			button {
				border-radius: 1px;
			}
			.footer-view {
				position: fixed;
				left: 0;
				bottom: 0;
				margin: 0;
				width: 100%;
				height: 50px;
				padding: 0;
			}
			.footer-view .mui-btn-block {
				width: 50%;
				height: 100%;
				margin: 0;
				/*padding: 0;*/
				font-size: 16px;
			}
			button:nth-child(2):active {
				background-color: #F0F0F0;
				border: 1px solid #dedede;
				color: #333;
			}
			button:nth-child(3):active {
				background-color: #FF9900;
				border: 1px solid #FF9900;
			}
			button:nth-child(4):active {
				background-color: #FF9900;
				border: 1px solid #FF9900;
			}
		</style>
	</head>
	<body id="main" >
		<div class="base_style_color " id='BarAppearance' style="height: 22px;width: 100%"></div>
		<div class="base_navigation_bar base_style_color base_navigation_item_bar ">
			<a class="base_left_item" href="#" onclick="backWindow()"> <img class="base_back_icon" src="../../image/icon_jiantou.png" alt=""> </a>
			<span id="title">小组讨论</span>
			<a class="base_right_item base_hide_item" href="#"> </a>
		</div>
		<div class="footer-view" >
			<button id="sumbit_bt1" type="button" class="mui-btn-warning horcenter btn_submit " onclick="JoinComment()" style="display: none">
				发表讨论
			</button>
			<button id="sumbit_bt2" type="button" class="mui-btn-block horcenter1 btn_submit1 " onclick="JoinComment()" style="display: none">
				发表讨论
			</button>
			<button id="sumbit_bt3" type="button" class="mui-btn-block horcenter2 btn_submit2 " onclick="CloseClassDissuss()" style="display: none">
				关闭
			</button>
			<button id="sumbit_bt4" type="button" class="mui-btn-block horcenter2 btn_submit2 " onclick="summary()" style="display: none">
				总结
			</button>
		</div>
	</body>
	<script type="text/javascript" src="../../script/jquery.min.js"></script>
	<script type="text/javascript" src="../../script/util.js"></script>
	<script src="../../script/common.js"></script>
	<script type="text/javascript" src="../../script/databaseOperation.js"></script>
	<script type="text/javascript" src="../../script/url.js"></script>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript" src="../../script/utils.js"></script>
	<script type="text/javascript" src="../../script/push.js"></script>
	<script type="text/javascript">
		var pid = "";
		// 计划id
		var cid = "";
		//课程id
		var chapterid = "";
		//章节id
		var title = "";
		var group_id = "";
		apiready = function() {
			sendBuriedNotifi('0', '小组讨论列表页', '035');
			//接收通知信息
			ReceivePopNotifi();
			var pageParam = api.pageParam;
			$('#title').text(api.pageParam.title);
			if (api.pageParam.type != 1) {//从列表进入
				DiscussClassType(1);
			} else {//创建小组讨论后进入
				$('#sumbit_bt2').show()
				$('#sumbit_bt3').show()
				group_id = api.pageParam.classid;
				addframe(api.pageParam.classid);
			}
			$api.setStorage('PanelDiscussionGroupId', group_id);
			//开始刷新
//			startGroupDiscussUpdate();
		};
		//退出页面
		function backWindow() {
			sendBuriedNotifi('1', '小组讨论列表页', '035');
			api.closeWin({
				name : 'CreateTeam',
			});
			api.closeWin({
			});
		}

		//发送埋点通知
		function sendBuriedNotifi(busionessid, pagetype, pagetypeid) {
			var userinfo = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				uname : $api.getStorage('cfnetppusername'),
				pid : api.pageParam.pid,
				cid : api.pageParam.cid,
				vid : api.pageParam.chapterid,
			}
			var data = {
				busionessid : busionessid,
				pagetype : pagetype,
				pagetypeid : pagetypeid,
				sourceurl : api.pageParam.sourceurl,
				sourcetitle : api.pageParam.sourcetitle,
				accesspageurl : window.location.pathname,
				accesspagetitle : document.title,
				userinfo : userinfo
			}
			SendBehaviorTrajectoriesNotifi_Study(data);
		}

		//判断身份
		function DiscussClassType(str) {
			var param = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				pid : api.pageParam.pid,
				cid : api.pageParam.cid,
				vid : api.pageParam.chapterid,
			};
			cfnetppPOST(url_isDiscussClass, param, true, function(data, status) {
				hideProgress();
				if (status == 'success') {
					if (data.code == 200) {
						group_id = data.data[0].id;
						if (str != 2) {
							addframe(data.data[0].id);
						}
						if ($api.getStorage('cfnetppuid') == data.data[0].uid) {//是小组长
							if (data.data[0].status == 0) {//未关闭
								$('#sumbit_bt2').show()
								$('#sumbit_bt3').show()
								$('#sumbit_bt4').hide()
							} else if (data.data[0].status == 1) {//已关闭
								$('#sumbit_bt2').show()
								$('#sumbit_bt3').hide()
								$('#sumbit_bt4').show()
							} else {//已总结
								$('#sumbit_bt2').hide()
								$('#sumbit_bt3').hide()
								$('#sumbit_bt4').hide()
								FrameChange();
							}
						} else {//不是小组长
							$('#sumbit_bt2').hide()
							$('#sumbit_bt3').hide()
							$('#sumbit_bt4').hide()
							if (data.data[0].status == 0) {//未关闭状态
								$('#sumbit_bt1').show()
							} else {
								$('#sumbit_bt1').hide()
								FrameChange();
							}
						}
					} else {
						if (data.code == 108 || data.code == 109) {
							addframe('');
						} else {
							api.toast({
								msg : '无数据',
								duration : 2000,
								location : 'bottom'
							});
						}
					}
				} else {
					api.toast({
						msg : '获取数据失败',
						duration : 2000,
						location : 'bottom'
					});
				}
			});
		}

		//Frame页发生改变
		function FrameChange() {
			var y = $('.base_navigation_bar').height() + 22;
			var h = api.winHeight - y;
			api.setFrameAttr({
				name : 'Student_PanelDiscussionFrame',
				rect : {
					x : 0,
					y : y,
					w : 'auto',
					h : h
				},
			});
		}

		//打开小组讨论总结页面
		function summary() {
			api.openFrame({
				name : 'Study_PanelDiscuss_AddSummary',
				url : 'Study_PanelDiscuss_AddSummary.html',
				pageParam : {
					pid : api.pageParam.pid,
					cid : api.pageParam.cid,
					vid : api.pageParam.chapterid,
					title : api.pageParam.title,
					group_id : group_id ,
				},
				reload : true,
			});
		}

		//关闭小组讨论
		function CloseClassDissuss() {
			var param = {
				id : group_id,
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				status : 1,
			};
			cfnetppPOST(url_closeClassDissuss, param, true, function(data, status) {
				hideProgress();
				SendBusinessOperationsLogNotifi('小组讨论列表页', '035', param, param, '', data, '关闭当前小组讨论接口', '035-01')
				if (status == 'success') {
					if (data.code == 200) {
						ShowToast('关闭成功');
						api.sendEvent({
							name : 'closePanelDiscussNotifi'
						});
						$('#sumbit_bt3').hide()
						$('#sumbit_bt4').show()
					} else {
						api.toast({
							msg : '关闭失败',
							duration : 2000,
							location : 'bottom'
						});
					}
				} else {
					api.toast({
						msg : '获取数据失败',
						duration : 2000,
						location : 'bottom'
					});
				}
			});
		}

		//接受通知
		function ReceivePopNotifi() {
			api.addEventListener({
				name : 'RefreshSummaryListNotifi'
			}, function(ret, err) {
				api.closeWin({
				});
				FrameH();
			});
			//接受阿里云推送，一旦关闭当前小组讨论，如果不是小组长身份,立即隐藏底部的发布讨论按钮
			api.addEventListener({
				name : 'pushMessageGroupDiscussion'
			}, function(ret, err) {
				var notifiJid = ret.value.jid;
				var DC_TYPE = ret.value.type;
				if (notifiJid == $api.getStorage('cfnetppjxid')) {
					//如果是当前小组讨论
					if (ret.value.id == $api.getStorage('PanelDiscussionGroupId')) {
						if (DC_TYPE == 10055) {
							DiscussClassType(2);
						}
					}
				}
			});
		}

		//打开页面
		function addframe(sgroup_id) {
			var y = $('.base_navigation_bar').height() + 22;
			var h = api.winHeight - y - 54;
			api.openFrame({
				name : 'Student_PanelDiscussionFrame',
				url : 'Student_PanelDiscussionFrame.html',
				rect : {
					x : 0,
					y : y,
					w : 'auto',
					h : h
				},
				pageParam : {
					pid : api.pageParam.pid,
					cid : api.pageParam.cid,
					chapterid : api.pageParam.chapterid,
					group_id : sgroup_id,
					title : api.pageParam.title,
					bewrite : api.pageParam.bewrite,
					tyep : api.pageParam.type
				},
				reload : true,
				bounces : false,
				vScrollBarEnabled : true,
				hScrollBarEnabled : false,
			});
		}

		//发表讨论窗口
		function JoinComment() {
			api.openFrame({
				name : 'Study_PanelDiscuss_AddDisscuss',
				url : 'Study_PanelDiscuss_AddDisscuss.html',
				pageParam : {
					pid : api.pageParam.pid,
					cid : api.pageParam.cid,
					chapterid : api.pageParam.chapterid,
					title : api.pageParam.title,
					group_id : group_id ,
				},
			});
		}

		//系统返回键事件
		function backKey() {
			api.addEventListener({
				name : 'keyback'
			}, function(ret, err) {
				if (api.pageParam.type != 1) {
					api.closeWin({
					});
				} else {
					api.closeToWin({
						name : 'New_Student_FreeCourse_DiscussChapterWindow'
					});
				}
			});
		}
	</script>
</html>
